<?php

namespace App\Http\Controllers\admin;



class LoginController extends BaseController
{
    public function index()
    {
        if (auth('admin')->check()) {
            return redirect('/admin');
        }

        return view('admin.login.login', [
            'site_name' => env('app_name', '管理后台')
        ]);
    }

    public function login()
    {
        $remember = $this->request->post('remember');

        $validate_data = $this->request->validate([
            'username' => 'bail|required',
            'password' => 'required',
        ]);

        $credentials = array_merge($validate_data, ['status' => 1]);
        if (auth('admin')->attempt($credentials, $remember == 'on')) {
            return $this->success('登录成功');
        } else {
            return $this->error('用户名或密码错误');
        }
    }

    public function logout()
    {
        auth('admin')->logout();

        return $this->success('退出成功');
    }
}
